package com.example.service.impl;

import com.example.dao.RecordMapper;
import com.example.domain.Record;
import com.example.domain.User;
import com.example.entity.PageResult;
import com.example.service.RecordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RecordServiceImpl implements RecordService {

    @Autowired
    private RecordMapper recordMapper;

    @Override
    public Boolean addRecord(Record record) {
        return recordMapper.addRecord(record) > 0;
    }
    /*
     * 新增记录
     */

    @Override
    public PageResult searchRecords(Record record, User user,
                                    Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        if (!"ADMIN".equals(user.getRole())) {
            record.setBorrower(user.getName());
        }

        Page<Record> page =recordMapper.searchRecords(record);

        return new PageResult(page.getTotal(), page.getResult());
    }
    /*
     *
     */


}
